package com.luck.easyfoodbatch.ui;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.luck.easyfoodbatch.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class BaseYdxHttpActivity extends BaseActivity {
    @BindView(R.id.wb)
    WebView wb;
    private int flag = 0;
    private String title = "";
    private String url = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        flag = getIntent().getIntExtra("flag", 0);
        if (flag == 1) {
            title = "货物保价和赔偿说明";
            url = "file:///android_asset/goods.html";
        } else if (flag == 2) {
            title = "拒收限运及违禁品说明";
            url = "file:///android_asset/guizhe.html";
        } else if (flag == 3) {
            title = "运东西平台增值服务收费标准";
            url = "file:///android_asset/fee.html";
        } else {
            title = "运东西物流服务条款";
            url = "file:///android_asset/ydx.html";
        }
        setContentView(R.layout.activity_base_http, title, MODE_BACK_NAVIGATION);
        ButterKnife.bind(this);
        wb.getSettings().setDefaultTextEncodingName("utf-8");
        wb.getSettings().setJavaScriptEnabled(true);
        wb.setWebChromeClient(new WebChromeClient());
        //设置 缓存模式
        wb.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
        // 开启 DOM storage API 功能
        wb.getSettings().setDomStorageEnabled(true);
        wb.loadUrl(url);
        wb.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // 重写此方法表明点击网页里面的链接还是在当前的webview里跳转，不跳到浏览器那边
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }
        });
    }
}
